package com.demo.controller;


import com.demo.entity.DvtDiagnose;
import com.demo.response.Result;
import com.demo.service.IDvtDiagnoseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * dvt诊断评估表 前端控制器
 * @author zm
 * @since 2020-12
 */
@RestController
@RequestMapping("/dvtDiagnose")
@Api(tags = "dvt诊断评估")
public class DvtDiagnoseController {
    @Autowired
    IDvtDiagnoseService dvtDiagnoseService;

    @ApiOperation("新增dvt诊断评估")
    @PostMapping("/addDvtDiagnose")
    public Result addDvtDiagnose(@Validated @RequestBody DvtDiagnose dvtDiagnose, BindingResult result) throws Exception {
        if (result.hasErrors()){
            return Result.error(result.getFieldError().getDefaultMessage());
        }
        return dvtDiagnoseService.addDvtDiagnose(dvtDiagnose);
    }

    @ApiOperation("编辑dvt诊断评估")
    @PostMapping("/updateDvtDiagnose")
    public Result updateDvtDiagnose(@RequestBody DvtDiagnose dvtDiagnose, BindingResult result) throws Exception {
        if (result.hasErrors()){
            return Result.error(result.getFieldError().getDefaultMessage());
        }
        return dvtDiagnoseService.updateDvtDiagnose(dvtDiagnose);
    }

    @ApiOperation("删除dvt诊断评估")
    @GetMapping("/deleteDvtDiagnose")
    public Result deleteDvtDiagnose(@RequestParam(name = "deletedUserId",required = true)Integer deletedUserId,
                                    @RequestParam(name = "dvtDiagnoseId",required = true)Integer dvtDiagnoseId){
        return dvtDiagnoseService.deleteDvtDiagnose(deletedUserId, dvtDiagnoseId);
    }

    @ApiOperation("查询dvt诊断评估列表")
    @GetMapping("/dvtDiagnoseList")
    public Result dvtDiagnoseList(@RequestParam(name = "pageNumber",required = false,defaultValue = "1")Integer pageNumber,
                                  @RequestParam(name = "pageSize",required = false,defaultValue = "10")Integer pageSize,
                                  @RequestParam(name = "patientId",required = false)Integer patientId,
                                  @RequestParam(name = "dvtItemId",required = false)Integer dvtItemId){
        return dvtDiagnoseService.dvtDiagnoseList(pageNumber, pageSize, patientId, dvtItemId);
    }

    @ApiOperation(value = "DVT--医生签字")
    @GetMapping("/doctorsSignatureVte")
    public Result doctorsSignatureVte(@RequestParam(name = "dvtDiagnoseId")Integer dvtDiagnoseId,
                                     @RequestParam(name = "signUserId",required = false)Integer signUserId,
                                     @RequestParam(name = "userPass")String userPass) throws Exception {
        dvtDiagnoseService.doctorsSignatureVte(dvtDiagnoseId, signUserId, userPass);
        return Result.success();
    }

}
